<!--  -->
<template>
  <div>
    <el-card>
      <el-form :inline="true">
        <el-form-item label="机构名称">
          <el-input v-model="params.name" style="width: 200px;" clearable placeholder="请输入机构名称"></el-input>
        </el-form-item>
        <el-form-item label="管理员姓名">
          <el-input v-model="params.adminName" clearable placeholder="请输入机构名称"></el-input>
        </el-form-item>
        <el-form-item label="">
          <el-button type="primary" @click="search">查询</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <el-button v-button="3" @click="addCompany" type="primary">新增机构</el-button>

      <EleTtable :data="tableData.list" :columns="columns" :total="tableData.counts">
       <template #city="{row}">
         {{ row.province}} {{row.city }}
      </template>
      <template #action="{row}">
        <el-button v-button="4" @click="edit(row.id)" type="primary">编辑</el-button>
      </template>
      </EleTtable>

  </div>
</template>

<script lang='ts' setup>
import { reactive, toRefs, ref, onMounted } from 'vue'
import { useRouter } from 'vue-router';
import { Company, CompanyParams, ResponseCompany } from '../../apis/company/type';
import { getCompanyList } from '../../apis/company/company';
import EleTtable, { ColumnType } from '../../components/table/EleTtable.vue';
const router = useRouter();
const columns = ref<ColumnType[]>([

  {
    label: "序号",
    prop: "id"
  },
  {
    label: "机构名称",
    prop: "name"
  },
  {
    label: "区域",
    prop: "province",
    slot:true,
    slotName:"city"
  },
  {
    label: "操作",
    prop: "action",
    slot:true,
    slotName:"action"
  },
  


]);

const params = reactive<CompanyParams>({
  adminName: "",
  name: "",
  page: 1,
  pageSize: 10
})

//机构列表

let tableData = reactive<ResponseCompany>({
  counts: 0,
  pageSize: 0,
  list: []
});
//搜索
const search = () => {
  params.page = 1;
  getCompanyData();
}
const edit=(id:number)=>{

  router.push(`/company/edit/${id}`)
}

const addCompany=()=>{
  router.push(`/company/add`)

  // router.push(`/alvie`)
}
//请求数据

const getCompanyData = async () => {

  const res = await getCompanyList(params);

  Object.assign(tableData, res.data)



}
getCompanyData();


 
</script>
<style scoped></style>